/*
 *    This file is part of SSHTunneler.
 *
 *    Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
 *
 *    SSHTunneler is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    SSHTunneler is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with SSHTunneler.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package sshtunneler.tools;

import java.awt.MenuItem;
import java.io.IOException;

import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

public class RunPuttyTool extends Tool {

	JMenuItem mnu_tunnels = new JMenuItem("Open Putty connection");

	public RunPuttyTool() {
		super("RunPuttyTool", "RunPuttyTool");
	}

	@Override
	public JMenuItem get_tunnel_tools_menu(boolean server_connected,
			boolean tunnel_connected) {
		this.mnu_tunnels.setEnabled(false);

		if (tunnel_connected) {
			this.mnu_tunnels.setEnabled(true);
		}
		return this.mnu_tunnels;
	}

	@Override
	public JMenuItem get_server_tools_menu(boolean server_connected) {
		return null;
	}

	@Override
	public MenuItem get_tray_tools_menu() {
		return null;
	}

	@Override
	public JMenuItem get_main_tools_menu() {
		return null;
	}

	@Override
	public void run() {
		String cmdLine = this.getProperty("putty_path") + " -ssh -P "
				+ this.currentTunnel.getLocalPort() + " localhost";

		try {
			Runtime.getRuntime().exec(cmdLine);
		} catch (IOException ex) {
			JOptionPane.showMessageDialog(null, ex.getMessage(),
					"Error launching putty ...", JOptionPane.ERROR_MESSAGE);
		}
	}

	@Override
	public void init_properties() {
		this.properties.put("putty_path", "D:\\Programs\\putty0.58.exe");
	}
}
